home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Environments
/
CGIshell 1.3.2
/
Pocket 6.5
/
Documents
/
Some Questions Answered
< prev
Wrap
Text File
|
1995-11-11
|
8KB
|
202 lines
Are there any books about this?
To learn Forth: _Starting FORTH_ by Leo Brodie (ISBN 0-13-843079-9).
Some other Forth books that I have read are:
_Thinking FORTH_ also by Brodie (ISBN 0-13-917568-7)
_Forth Fundamentals_ by McCabe (ISBN 0-88056-091-6)
_Library of Forth Routines and Utilities_ by Terry (ISBN 0-452-25841-3)
_Threaded Interpretive Languages_ by Loeliger (ISBN 0-07-038360-X)
_Dr Dobbs Toolbook of Forth_ by Dr. Dobbs (ISBN 0-934375-41-0)
Here are some books that apply to Macintosh assembly or toolbox
programming:
_Inside Macintosh_, many volumes, by Apple Computer, Addison Wesley
_Apple Numerics Manual_ by Apple Computer, Addison Wesley
_Macintosh Revealed_ vols 1-4 by Stephen Chernicoff, Hayden Books
_M68000 16/32-Bit Microprossor Programmer's Reference Manual_,
Motorola Inc.
_The Complete Book of Macntosh Assembly Language Programming_,
vol 1 and 2 by Dan Weston, Scott Foresman and Company
_How to Write Macintosh Software_, by Scott Knaster, Addison Wesley
_Macintosh Programming Secrets_, by Scott Knaster and Keith Rollin,
Addison Wesley
_System 7 Revealed_ by Anthony Meadow, Addison Wesley
_Programming for System 7_ by Gary Little and Tim Swihart, Addison
Wesley
_____________________________________
How can I make a stand alone program with Pocket Forth?
To make a Turnkey application
1) Make a copy of the Pocket Forth application. Rename it.
2) Add resources that your application will need to the copy with
Resedit or equivalent. (Since you may have to do this several times, it
is convienent to put all the necessary resources into a file for safe
keeping.)
3) Run Pocket Forth and extend the language to handle whatever task
you want your application to do. Write an event loop as demonstrated in
the Turnkey section of the manual. Debug your code interactivly at this
point.
4) Assign handlers to the pertinant event variables and set other
variables to their default values. See the Events section of the
manual.
5) Finally save the Pocket Forth dictionary from the File menu or just
type save. Quit Pocket Forth
If all goes well, great, you've just created a program with Pocket
Forth. If the program crashes or otherwise functions incorrectly, start
over, but spend more time with step 3.
6) When finally the program works as you like, go back to resedit,
change the icons, BNDL, FREF, and creator signature, as well as the
balloon help resources.
That's about it. There is a trivial example in the manual, and a more
complex example with the Read Me application. The source is in the
example file, reader. The Contributions folder has many other examples.
_____________________________________
How does Pocket Forth compile code?
How Dictionary entries are defined:
Pocket Forth stores its own code in a DICT resource. The
DICT contains machine language and compiled data. For
example a word like '+' compiles a header:
DC.B 1,'+',0,0
which is the number of characters followed by the first three
characters of the word's name. If the name is less than three
characters (as in this case), zeros are compiled to fill the
four byte name field. (Only the 5 lsb's count for the length,
with the other bytes providing flags for the compiler to use.)
Then a two byte link field is compiled:
DC.W {relative address of the previous word in the list}
This field is used to search the dictionary for a word.
Next comes machine code to implement the word:
MOVE (A6)+,D0 ; A6 is the parameter stack pointer
ADD D0,(A6)
RTS
Notice the code ends with RTS. This is because the inner
interpreter of Pocket Forth is nothing more than the JSR/RTS
mechanism built into the processor. That also means that words
can only be pure machine code.
_____________________________________
How do I draw curves with Pocket Forth.
Here then is an excerpt from the Bezier code that draws Bezier curves.
Just paste the following code into the Pocket Forth window then type
TEST
to run the program:
-------------------------Cut Here------------------------------------
( BCurves Mon May 2, 1988 15:17:20 )
( the cubic bezier algorithm is from an article by )
( R. H. Turpin in MICRO no. 70 )
( Minimalized for clarity 10/28/93 )
2variable P0 \ Start point
2variable P1 \ Start Control point
2variable P2 \ End control point
2variable P3 \ End point
2variable P0' 2variable P1'
2variable P2' 2variable P3'
variable N
( point math )
: P- ( h0 v0 h1 v1 -- h0-h1 v0-v1 )
rot swap - rot rot - swap ;
: P* ( h v n -- n*h n*v ) rot over * rot rot * ;
: P*/ ( h v m n -- m*h/n m*v/n )
rot >r over over 2>r */ ( m*h/n )
2r> r> swap */ ; ( m*v/n )
: COMPUTE.P' ( -- ) \ fill in the primed variables
p1 2@ p0 2@ p- 3 p*
2dup p2 2@ p1 2@ p- 3 p*
2dup p3 2@ p0 2@ p- 2swap p-
p3' 2! 2swap p- p2' 2!
p1' 2! p0 2@ p0' 2! ;
: POINTS ( -- h0' v0' h1' v1' h2' v2' h3' v3' ) \ get primed points
p0' 2@ p1' 2@ p2' 2@ p3' 2@ ;
: P[T] ( p0' p1' p2' p3' t -- h[t] v[t] ) \ t= the step number
3 0 DO dup >r n @ p*/ d+ r> LOOP drop ;
: FIX.N ( -- ) \ set the number of steps
points 2 n ! 1 p[t]
p0 2@ p- abs swap abs max
3 max 100 min n ! ;
: >P0 ( -- ) p0 2@ !pen ; \ put the pen at the start point
: CURVE ( -- ) \ draw from point to point
@pen \ hold the pen location
>p0 n @ 1+ 1 DO \ repeat the following with r=1 to n+1
points r p[t] -to \ calculate and draw to the next point
LOOP !pen ; \ restore the pen location
: BDRAW ( -- ) \ draw the curve described in P0,P1,P2,P3
compute.p' fix.n curve ;
: TEST ( Set points, then draw )
300 50 p0 2! \ start point
-100 150 p1 2! \ start control
500 200 p2 2! \ end control
75 20 p3 2! \ end point
page bdraw ; \ draw the curve
---------------------------Cut To Here-------------------------------
_____________________________________
How are menus added?
How to add menus:
1. Make a COPY of Pocket Forth and open it with ResEdit.
2. First create a new menu resource.
3. Then set the menu resource number to 4 (press cmd-I).
4. You get a dialog to update the menu id to 4. Say yes!
5. Type in a menu title and add a menu item (cmd-K).
6. Title the item and add a cmd key and color if you like.
7. Quit ResEdit saving the _COPY_ of Pocket Forth.
8. Run the doctored copy of Pocket Forth.
9. Paste in the following code:
+++++++++++++++>> CUT FROM THE NEXT LINE <<+++++++++++++++++++
( Menu example Eek-lips day 4 Jan 1992. )
: util beep beep beep ; ( this represents your menu code )
create UteMenu ( a list of words for your menu items )
' util , ( there is just one item, see above. )
create NewMenuList ( a list of lists of your menubar )
18 +md @ @ , ( comma in addr of File menu list )
18 +md @ 2+ @ , ( ditto for Edit menu list )
UteMenu , ( and now Your menu )
2variable nmenuh ( to hold the handle to the menu )
: close ( Menus leave memory blocks that must be cleaned up )
nmenuh 2@ 2>r ,$ A9A3 ( _ReleaseResource )
[ 22 +md @ compile ( do the regular quit routine )
' close 22 +md ! ( store the new close routine )
: +menu ( Turn the new menu on.)
NewMenuList 18 +md ! ( store the new menubar list )
0 0 2>r 4 >r ,$ A9BF ( _GetRMenu )
2r> 2dup 2>r 0 >r ,$ A935 ( _InsertMenu )
nmenuh 2! ,$ A937 ; ( _DrawMenuBar )
+menu
++++++++++++++>> CUT TO THE PREVIOUS LINE <<++++++++++++++++++
_____________________________________
Why did I do this?
Because it wasn't there.